package com.ht.medicaltreatment.viewmodel

import com.blankj.utilcode.util.ToastUtils
import com.hjq.http.EasyHttp
import com.hjq.http.listener.OnHttpListener
import com.ht.medicaltreatment.api.ConsumableApprovalAPI
import com.ht.medicaltreatment.bean.ApplyRecordData
import com.ht.medicaltreatment.bean.ConsumableApplyRecordBean
import com.ht.medicaltreatment.bean.UserInfoBean
import com.ht.medicaltreatment.bean.UserInfoData

class SendOffViewModel:BaseViewModel() {
    fun getUserList(onSuccess:(MutableList<UserInfoData>)->Unit){
        EasyHttp.post(this)
            .api("/other/app_user/queryAllUser.do")
            .request(object : OnHttpListener<UserInfoBean>{
                override fun onHttpSuccess(result: UserInfoBean) {
                    onSuccess(result.data)
                }

                override fun onHttpFail(e: Exception) {
                    ToastUtils.showShort(e.message)
                }
            })
    }

    fun approval(api:ConsumableApprovalAPI,onSuccess:(ApplyRecordData)->Unit){
        EasyHttp.post(this)
            .api(api)
            .request(object : OnHttpListener<ConsumableApplyRecordBean>{
                override fun onHttpSuccess(result: ConsumableApplyRecordBean) {
                    onSuccess(result.data)
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message?:"请求失败")
                }
            })
    }
}